<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Users</title>
    <!--新bootstrap4核心css文件-->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <!--bootstrap.bundle.min.js用于弹窗、提示、下拉菜单，包含了popper.min.js-->
    <script src="http://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <!--最新的bootstrap4核心JavaScript文件-->
    <script src="http://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script>
        function isNull(str) {
            if (str == "")
                return true;
            var regu ="^[]+$";
            var re = new RegExp(regu);

            return re.test(str);
        }
        $(function () {
            $("#btn4showhide").click(function () {
                if ($("#div4addUser").is(":hidden"))
                    $("#div4addUser").show();
                else
                    $("#div4addUser").hide();
            });
            $("#add").click(function () {
                var nameVal = $("#name").val();
                var pwdVal = $("#pwd").val();
                var roleVal = $("#role option:selected").text();
                if (isNull(nameVal)||isNull(pwdVal)||isNull(roleVal)){
                    confirm("请完善信息");
                    return;
                }
                var param = {
                    "name":nameVal,
                    "password":pwdVal,
                    "role":roleVal
                };
                $.ajax({
                    url:"/addUser",//请求url
                    data:param,//请求参数
                    async:true,//是否异步
                    success:function f(result) {
                        window.confirm(result.msg);//新增用户成功提示框
                        location.href = "users";//重新加载界面，同步数据库信息
                    }
                });
            });
        });
    </script>
    <style>
        body{background: #cc9966}
        .col-md-6{margin:0 auto; width:400px; height:50px; text-align: center}
        .pagination{margin:0 auto; width:400px; height:50px;}
        .model-foot li{width:100px;height:30px;float:left;text-align:center;line-height:20px}
    </style>
</head>
<body>
<div id="selectResult">
    <table class="table table-dark table-hover">
        <thead>
        <tr>
            <th>用户ID</th>
            <th>用户名称</th>
            <th>用户密码</th>
            <th>用户权限</th>
            <th>注销用户</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="user:${userList}">
            <td th:text="${user.id}"></td>
            <td th:text="${user.name}"></td>
            <td th:text="${user.password}"></td>
            <td th:text="${user.role}"></td>
            <td>
                <a th:href="@{/deleteUser+{id}(id=${user.id})}" id="delete">注销</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<div class="model-foot no-margin-top">
    <div class="col-md-6">
        <strong>当前第[[${pageInfo.pageNum}]]页[[${pageInfo.pages}]]页.一共[[${pageInfo.total}]]条记录</strong>
    </div>
    <ul class="pagination pull-right no-margin">
        <li th:if="${pageInfo.hasPreviousPage}">
            <a th:href="'users?pageNum=1'">首页</a>
        </li>
        <li class="prev" th:if="${pageInfo.hasPreviousPage}">
            <a th:href="'users?pageNum='+${pageInfo.prePage}">
                <i class="ace-icon fa fa-angle-double-left"></i>
            </a>
        </li>
        <!--遍历条数-->
        <li th:each="nav:${pageInfo.navigatepageNums}">
            <a th:href="'users?pageNum='+${nav}" th:text="${nav}" th:if="${nav != pageInfo.pageNum}"></a>
            <span style="font-weight: bold;background: #cc9966;" th:if="${nav == pageInfo.pageNum}" th:text="${nav}"></span>
        </li>
        <li class="next" th:if="${pageInfo.hasNextPage}">
            <a th:href="'users?pageNum='+${pageInfo.nextPage}">
                <i class="ace-icon fa fa-angle-double-right"></i>
            </a>
        </li>
        <li>
            <a th:href="'users?pageNum='+${pageInfo.pages}">尾页</a>
        </li>
    </ul>
</div>
</body>
</html>